package com.major.recursion.queen8;

public class Queen8 {
    int max = 8;
    int[] array = new int[max];

    public static void main(String[] args) {
        Queen8 queen8 = new Queen8();
        queen8.check(0);
    }

    private void check(int n) {
        if(n == max) {  //n = 8 , 其实8个皇后就既然放好
            print();
            return;
        }
        for(int lie = 0; lie < max; lie++) {
            array[n] = lie;
            if(judge(n)) { // 不冲突
                check(n+1); //
            }

        }
    }

    private boolean judge(int n) {
        for(int j = 0; j < n; j++) {
            if(array[j] == array[n] || Math.abs(n-j) == Math.abs(array[n] - array[j]) ) {
                return false;
            }
        }
        return true;
    }

    private void print() {
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();
    }
}
